<?php
    include __DIR__ . '/../application/common/lib/Redis.php';
    $config = include __DIR__ . '/../application/client/config/config.php';
    
    $wxConfig = $config['wx'];
    
    
    $result = file_get_contents("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$wxConfig['appid']}&secret={$wxConfig['secret']}");
    if(empty($result)) {
        exit;
    }
    
    $result = json_decode($result, true);
    if(empty($result) || empty($result['access_token'])) {
        exit;
    }
    
    $redis = new \app\common\lib\Redis();
    
    $redis->setex('wx_access_token', $result['access_token'], $result['expires_in']);
    
    $redis->close();